package org.example.messagewall.demos.controller;
import org.example.messagewall.demos.model.MessageInfo;
import org.example.messagewall.demos.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;


 @RequestMapping("/put")
  public boolean put(MessageInfo message){
     if(!StringUtils.hasLength(message.getFrom()) || !StringUtils.hasLength(message.getTo()) || !
        StringUtils.hasLength(message.getMessage())){
       return false ;
     }
      this.messageService.addMessageInfo(message);
     return true ;
 }

 @RequestMapping("/get")
    public List<MessageInfo> get(){
     return this.messageService.getMessageInfoList();

 }
}
